<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;

use App\Http\Requests;


class TuiguangController extends CommonController
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $data = \DB::table("tuiguang")->paginate(5);
		return view("admin.tuiguang.index",['list'=>$data]);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view("admin.tuiguang.create");
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
         $data = $_POST;
	   unset($data['_token']);
	   
	   $id = \DB::table("tuiguang")->insertGetId($data);
	   //判断
        if($id>0){
            $info = "添加成功！";
        }else{
            $info = "添加失败！";
        }
        
       return redirect("admin/tuiguang")->with("err",$info);
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $data = \DB::table("tuiguang")->where('id',$id)->first();
		return view("admin.tuiguang.edit",['list'=>$data]);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
         $data = $_POST;
		unset($data['_token']);
		unset($data['_method']);
		
		$id = \DB::table("tuiguang")->where("id",$id)->update($data);
		
		//判断
        if($id>0){
            $info = "类别信息修改成功！";
        }else{
            $info = "类别信息修改失败！";
        }
        
       return redirect("admin/tuiguang")->with("err",$info);
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        \DB::table('tuiguang')->delete($id);
        return redirect("admin/tuiguang")->with("err","删除成功！");
    }
}
